import type { DoctorPage, KnowledgePage, KnowledgeParams, PageParams, FollowType, TopDep, ConsultOrderPreData, ConsultOrderPreParams, ConsultOrderItem, PartialConsult, Image, ConsultOrderListParams, ConsultOrderPage } from '@/types/consult'
import { request } from '@/utils/request'
export const getKnowledgePage = (params: KnowledgeParams) => 
    request<KnowledgePage>('/patient/home/knowledge', 'GET', params)
export const getDoctorPage = (params: PageParams) => 
    request<DoctorPage>('/home/page/doc', 'GET', params)
export const followOrUnfollow = (id: string, type: FollowType = 'doc') => 
    request('like', 'POST', {id, type})

export const getAllDep = () => request<TopDep[]>('dep/all')
//上传图片接口
export const uploadImage = (file: File) => {
    //FormData是浏览器提供的WebAPI，用于构造表单数据，通常用于文件上传或表单提交，它不需要额外导入，是现代浏览器原生支持的 API
    const fd = new FormData()
    /* 向FormData对象中添加了一个字段，第一个file是字段名，服务器根据这个名称获取文件，第二个file是要上传的文件对象也就是函数的参数 */
    fd.append('file', file)
    return request<Image>('upload', 'POST', fd)
}

//预支付信息
export const getConsultOrderPre = (params: ConsultOrderPreParams) => request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', params)

//生成问诊订单
export const createConsultOrder = (data: PartialConsult) => 
    request<{id: string}>('/patient/consult/order', 'POST', data)

//生成支付地址 0是微信 1是支付宝
export const getConsultOrderPayUrl = (params: {
    paymentMethod: 0 | 1
    orderId: string
    payCallback: string
}) => request<{payUrl: string}>('/patient/consult/pay', 'POST', params)

//获取订单详情
export const getConsultOrderDetail = (orderId: string) => 
    request<ConsultOrderItem>('/patient/consult/order/detail', 'GET', { orderId })

//根据id获取原始处方
export const getPresctiptionPic = (id: string) => 
    request<{ url: string }>(`/patient/consult/prescription/${id}`)

//评价医生
export const evaluateConsultOrder = (data: {
    docId: string
    orderId: string
    score: number
    content: string
    anonymousFlag: 0 | 1
}) => request('/patient/order/evaluate', 'POST', data)

//问诊订单api
export const getConsultOrderList = (params: ConsultOrderListParams) => 
    request<ConsultOrderPage>('patient/consult/order/list', 'GET', params)

//取消订单接口
export const cancelOrder = (id: string) => request(`/patient/order/cancel/${id}`, 'PUT')

//删除订单
export const deleteOrder = (id: string) => request(`/patient/order/${id}`, 'DELETE')